﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SLG.Domain.Strategy
{
    /// <summary>
    /// 为第一次创建王国的时候，在主城创建默认的资源
    /// </summary>
    class DefaultResourceStrategy
    {   
        public static void Build(SLGDbContext dbContext, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            EntRep<Entities.T_Resource> bRep = new EntRep<Entities.T_Resource>(dbContext);

            BuildFoods(bRep, serverId, userId, kingdomId, cityId, ref now);

            BuildWood(bRep, serverId, userId, kingdomId, cityId, ref now);

            BuildGold(bRep, serverId, userId, kingdomId, cityId, ref now);
        }

        private static void BuildFoods(EntRep<Entities.T_Resource> rep, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            Entities.T_Resource foods = new Entities.T_Resource();
            foods.Id = DEF.ResourceTypes.Foods;
            foods.CityId = cityId;
            foods.ServerId = serverId;
            foods.UserId = userId;
            foods.KingdomId = kingdomId;
            foods.Value = 5000;
            foods.Rate = 5;
            foods.LiquidatedTime = now;
            rep.Create(foods);
        }

        private static void BuildWood(EntRep<Entities.T_Resource> rep, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            Entities.T_Resource wood = new Entities.T_Resource();
            wood.Id = DEF.ResourceTypes.Wood;
            wood.CityId = cityId;
            wood.ServerId = serverId;
            wood.UserId = userId;
            wood.KingdomId = kingdomId;
            wood.Value = 3000;
            wood.Rate = 3;
            wood.LiquidatedTime = now;
            rep.Create(wood);
        }

        private static void BuildGold(EntRep<Entities.T_Resource> rep, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            Entities.T_Resource gold = new Entities.T_Resource();
            gold.Id = DEF.ResourceTypes.Gold;
            gold.CityId = cityId;
            gold.ServerId = serverId;
            gold.UserId = userId;
            gold.KingdomId = kingdomId;
            gold.Value = 1000;
            gold.Rate = 1;
            gold.LiquidatedTime = now;
            rep.Create(gold);
        }
    }
}
